#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include "../vector.h"

int main() {
    // 设置区域为中文UTF-8
    setlocale(LC_ALL, "zh_CN.UTF-8");
    
    printf("=== Vector简单测试 ===\n");
    
    // 创建int类型vector
    Vector* int_vector = VectorNew(VECTOR_TYPE_INT, 5);
    printf("创建int vector成功，初始大小: %zu\n", VectorSize(int_vector));
    
    // 添加元素
    printf("添加元素: 10, 20, 30, 40, 50\n");
    VectorAdd(int_vector, 10);
    VectorAdd(int_vector, 20);
    VectorAdd(int_vector, 30);
    VectorAdd(int_vector, 40);
    VectorAdd(int_vector, 50);
    
    // 打印元素
    printf("vector内容: ");
    for (size_t i = 0; i < VectorSize(int_vector); i++) {
        int* ptr = (int*)VectorGet(int_vector, i);
        if (ptr) {
            printf("%d ", *ptr);
        } else {
            printf("NULL ");
        }
    }
    printf("\n");
    
    // 测试修改元素
    printf("修改索引2为99\n");
    VectorSet(int_vector, 2, 99);
    printf("索引2的值: %d\n", *((int*)VectorGet(int_vector, 2)));
    
    // 测试删除元素
    printf("删除索引1的元素\n");
    VectorDelete(int_vector, 1);
    printf("删除后内容: ");
    for (size_t i = 0; i < VectorSize(int_vector); i++) {
        printf("%d ", *((int*)VectorGet(int_vector, i)));
    }
    printf("\n");
    
    // 测试double类型
    printf("\n测试double vector:\n");
    Vector* double_vector = VectorNew(VECTOR_TYPE_DOUBLE, 3);
    VectorAdd(double_vector, 1.1);
    VectorAdd(double_vector, 2.2);
    VectorAdd(double_vector, 3.3);
    
    printf("double vector内容: ");
    for (size_t i = 0; i < VectorSize(double_vector); i++) {
        printf("%lf ", *((double*)VectorGet(double_vector, i)));
    }
    printf("\n");
    
    // 清理内存
    VectorFree(int_vector);
    VectorFree(double_vector);
    
    printf("\n测试完成！\n");
    return 0;
}